#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;

int t, n, T, a, b;

pair<int, int> dat[N];
int dcnt;

int calc(int num0, int num1, int time)
{
    int x = min(num0, time / a);
    int ans = x + min(num1, (time - x * a) / b);
    return ans;
}

int main(int argc, char const *argv[])
{
    // freopen("in.txt", "r", stdin);
    scanf("%d", &t);
    for (int kk = 0; kk < t; ++kk)
    {
        scanf("%d%d%d%d", &n, &T, &a, &b);
        for (int i = 0; i < n; ++i)
        {
            int x;
            scanf("%d", &x);
            dat[i].second = (1 - x) * a + x * b;
        }
        int num0 = 0, num1 = 0;
        for (int i = 0; i < n; ++i)
        {
            scanf("%d", &dat[i].first);
            if (dat[i].second == a)
                ++num0;
            else
                ++num1;
        }
        sort(dat, dat + n);
        int mustTake = 0, ans = 0, tans = 0, must = 0;
        for (int i = 0; i < n;)
        {
            int freeTime = dat[i].first - 1 - mustTake;
            if (freeTime >= 0)
            {
                tans = calc(num0, num1, freeTime) + must;
                ans = max(ans, tans);
            }
            int j = i;
            while (j + 1 < n && dat[j + 1].first == dat[i].first)
            {
                ++j;
            }
            for (int k = i; k <= j; ++k)
            {
                ++must;
                mustTake += dat[k].second;
                if (mustTake > T) break;
                if (dat[k].second == a)
                    --num0;
                else
                    --num1;
            }
            if (mustTake > T) break;
            i = j + 1;
        }
        if (mustTake <= T)
            ans = max(ans, n);
        printf("%d\n", ans);
    }
    return 0;
}
